package com.weilus.controller.permission;

import com.weilus.config.security.SecurityMetadataSourcePropertity;
import com.weilus.controller.AdminController;
import com.weilus.dto.RespEntity;
import com.weilus.dto.request.PRoleDto;
import com.weilus.entity.SecurityGroup;
import com.weilus.service.permission.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
public class RoleController extends AdminController{
	
	@Autowired
	RoleService roleService;
	@Autowired
	SecurityMetadataSourcePropertity adminSecurityPropertity;


	@PostMapping("/role")
	public @ResponseBody RespEntity add(SecurityGroup role){
		return RespEntity.ok(roleService.add(role));
	}

	@DeleteMapping("/role/{id}")
	public @ResponseBody RespEntity delete(@PathVariable("id")Integer id){
		return RespEntity.ok(roleService.delete(id));
	}

	@PutMapping("/role")
	public @ResponseBody RespEntity update(SecurityGroup role){
		return RespEntity.ok(roleService.update(role));
	}

	@GetMapping("/role.html")
	public String queryRole(){
		return "permission/role_table";
	}

	@GetMapping("/role")
	public @ResponseBody RespEntity page(PRoleDto dto){
		return RespEntity.ok(roleService.page(dto));
	}

	@PutMapping("/role/{id}/right")
	public @ResponseBody RespEntity addRoleRight(
			@RequestParam(value="rightIds[]",required=false)List<String> rightIds,
			@PathVariable("id") Integer id){
		return RespEntity.ok(roleService.addRoleRight(id,rightIds));
	}
	
}
